package com.xypower.web.servlet;

import com.alibaba.fastjson.JSON;
import com.xypower.pojo.Classes;
import com.xypower.service.ClassesService;
import com.xypower.service.impl.ClassesServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
    private ClassesService classesService;

    @Override
    public void init() throws ServletException {
        classesService = new ClassesServiceImpl();
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf8");
//        1、查询得到所有班级
        List<Classes> classes = classesService.findAll();
        resp.getWriter().println(JSON.toJSONString(classes));
        resp.getWriter().flush();
    }
}
